package com.yu.thread4;

/**
 * Created by xiaolongyu on 15/1/23.
 */
public class Sample {

    private int number;

    public synchronized void increase(){
        if(number != 0){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("+++ increase:" + number);
        if(number == 0){
            number ++;
            System.out.println("+++ increase:" + number + " " + Thread.currentThread());
            notify();
        }

    }

    public synchronized void decrease(){
        if(number == 0){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("--- decrease:" + number);
        if(number != 0){
            number --;
            System.out.println("--- decrease:" + number + " " + Thread.currentThread());
            notify();
        }
    }
}
